<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
        <input type="text" name="" id="userinp">
        <input type="password" name="" id="pwdinp">
        <button>submit</button>
    <script>
    var btn=document.getElementsByTagName("button")[0]
    var user=document.getElementById("userinp")
    var pwd=document.getElementById("pwdinp")
    btn.onclick=function(){
        console.log(getcookie("user_"+user.value))
    if(getcookie("user_"+user.value)){
         if(getcookie("pwd_"+user.value)==pwd.value){
              location.href="index.html"
         }
         else{
             alert("密码错误")
         }
    }
    else{
        alert("用户名不存在")
    }
    }
    
    function setcookie(name,value,d,path="/"){
        var date=new Date()
        date.setDate(date.getDate()+d)
        document.cookie=name+"="+value+";expires="+date+";path="+path
    } 
    function getcookie(name){
      if(document.cookie){
        var str=document.cookie
        var arr=str.split(";")
        for(var i=0;i<arr.length;i++){
            var key=arr[i].trim().split("=")[0]
            var value=arr[i].split("=")[1]
            if(key==name){
                return value
            }
        }   
      }
      return ""
    }
    </script>
</body>
</html>